import {
  createStore
} from 'vuex'
import axios from 'axios'
import persist from 'vuex-persistedstate'
export default createStore({
  state: {
    objList: [],
    flag: false
  },
  mutations: {
    push(state, value) {
      // let flag = false
      // state.objList.forEach((item) => {
      //   if (item == value) {
      //     flag = true
      //   }
      // })
      let flag = state.objList.findIndex(item => item == value)
      console.log(flag);
      // if (flag == -1) {
      //   state.objList.unshift(value)
      // } else {
      //   state.objList.splice(flag, 1)
      //   state.objList.unshift(value)
      // }
      if (flag > -1) {
        state.objList.splice(flag, 1)
      }
      state.objList.unshift(value)
    },
    remove(state, i) {
      state.objList.splice(i, 1)
    },
    clear(state) {
      state.objList = []
    },
    flagChange(state) {
      state.flag = true
    }
  },


  actions: {


  },
  plugins: [persist()]


})